package com.hhxy.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ResponseDemo1")
public class ResponseDemo1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ResponseDemo1被访问了");
        //方式一：原始写法
        /*response.setStatus(302);
        response.setHeader("location","http://localhost:8080/day7_servlet/ResponseDemo2");*/
        //方式二：使用sendRedirect方法
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/ResponseDemo2");

    }
}
